//
//  changepassViewController.m
//  car
//
//  Created by chenxu on 15/3/14.
//  Copyright (c) 2015年 chenxu. All rights reserved.
//

#import "changepassViewController.h"
#import "Login.h"
#import "NetAPIManager.h"

#define kCellIdentifier_InputOnlyTextPlain @"InputOnlyTextPlainCell"

@interface changepassViewController ()

@end

@implementation changepassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _myUser = [Login curLoginUser];
    //注册该cell
    [self.tableView registerClass:[InputOnlyTextPlainCell class] forCellReuseIdentifier:kCellIdentifier_InputOnlyTextPlain];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)submit:(id)sender {
    NSString* tip =  [_myUser changePasswordTips];

    if (tip) {
        [self showHudTipStr:tip];
    }
    else{
        [[NetAPIManager sharedManager] update_password:[_myUser toResetPasswordParams] andBlock:^(id data, NSError *error) {
            [self showHudTipStr:data];
        }];
    }
}


#pragma mark - table view
#pragma mark Table Data Source Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
#pragma mark Table Delegate Methods
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    InputOnlyTextPlainCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_InputOnlyTextPlain forIndexPath:indexPath];
    
    switch (indexPath.row) {
        case 0:
        {
            [cell configWithPlaceholder:@"请输入当前密码" valueStr:nil secureTextEntry:YES];
            cell.textValueChangedBlock = ^(NSString *valueStr){
                self.myUser.Password = valueStr;
            };
        }
            break;
        case 1:
        {
            [cell configWithPlaceholder:@"请输入新密码" valueStr:nil secureTextEntry:YES];
            cell.textValueChangedBlock = ^(NSString *valueStr){
                self.myUser.resetPassword = valueStr;
            };
        }
            break;
        default:
        {
            [cell configWithPlaceholder:@"请确认新密码" valueStr:nil secureTextEntry:YES];
            cell.textValueChangedBlock = ^(NSString *valueStr){
                self.myUser.resetPasswordConfirm = valueStr;
            };
        }
            break;
    }
  //  [self.tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:20];
    return cell;
    
    
}
@end
